package com.why.amallrest.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.why.common.utils.PageUtils;
import com.why.common.utils.Result;
import com.why.entity.ProductParamsEntity;
import com.why.service.ProductParamsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 商品参数 
 *
 * @author why
 * @email 1585049082@qq.com
 * @date 2021-10-24 20:16:08
 */
@RestController
@RequestMapping("mall/productParam")
public class ProductParamsController {
    @Autowired
    private ProductParamsService productParamsService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("why:productparams:list")
    public Result list(@RequestParam Map<String, Object> params){
        PageUtils page = productParamsService.queryPage(params);

        return Result.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/detail-params/{productId}")
    public Result info(@PathVariable("productId") String productId){
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("product_id", productId);
        ProductParamsEntity productParams = productParamsService.getOne(wrapper);

        return Result.ok().put("data", productParams);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
   /// @RequiresPermissions("why:productparams:save")
    public Result save(@RequestBody ProductParamsEntity productParams){
		productParamsService.save(productParams);

        return Result.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
   // @RequiresPermissions("why:productparams:update")
    public Result update(@RequestBody ProductParamsEntity productParams){
		productParamsService.updateById(productParams);

        return Result.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
   // @RequiresPermissions("why:productparams:delete")
    public Result delete(@RequestBody String[] paramIds){
		productParamsService.removeByIds(Arrays.asList(paramIds));

        return Result.ok();
    }

}
